package patterns.actions.iterator.books;

public class IteratorImp implements IteratorCls {
	private  AggregateImp agg;
	private int index=0;
	private int size=0;

	public IteratorImp(AggregateImp agg) {
		this.agg=agg;
		this.size=agg.size();
		this.index=0;
	}

	@Override
	public boolean hasNext() {
		return this.index<this.size;
	}

	@Override
	public Object next() {
		if(this.index<this.size){
			return this.agg.getElement(this.index++);
		}
		return null;
	}

}
